package com.powervision.mvvmdemo.ui.viewmodel

import com.powervision.base.base.BaseViewModel
import com.powervision.base.util.LogUtils
import com.powervision.http.observer.StateLiveData
import com.powervision.mvvmdemo.ui.model.ArticleListModel
import com.powervision.mvvmdemo.ui.repository.ArtListRepository

/**
 * @auth: njb
 * @date: 2021/12/14 16:36
 * @desc: 描述
 */
class ArtListViewModel : BaseViewModel() {
    private val repository by lazy { ArtListRepository() }

    val mLiveData = StateLiveData<ArticleListModel?>()

    fun artList(page: Int) {
        launchWithLoading(requestBlock = {
            repository.getArtList(page = page)
        }, resultCallback = { it ->
            mLiveData.value = it
            it.data?.datas?.forEach {
                LogUtils.d("--artlist--", it.author.toString())
            }
        })
    }
}